package com.yunji.app.base;

import com.yunji.base.business.AllianceBusiness;
import com.yunji.base.domain.AllianceDO;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.model.dto.LoginInfo;
import com.yunji.system.context.SystemContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Package com.yunji.app.user
 * FileName:	GateWayAllianceController.java
 * Copyright:	Copyright © 2024 云集互联 All Rights Reserved
 * Company:		云集互联
 * @version: 1.0
 * @since: JDK 1.8.0_202
 * Create at:   2024-04-02 19:19:46
 * Description:
 * 移动端-代理商加盟
 * Modification History:
 * Author					Date						Version			Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-02 19:19:46			1.0				1.0 Version
 */
@Api(tags = "移动端-代理商加盟")
@RestController
@RequestMapping("/gateway/alliance")
public class GateWayAllianceController extends BaseController {
    @Resource
    AllianceBusiness business;


    /**
     * 新增加盟
     */
    @ApiOperation("用户端-新增加盟")
    @PostMapping(value = "/addAlliance")
    public Response<String> add(@RequestBody AllianceDO sAlliance) {
        LoginInfo user = SystemContext.getUser();
        logger.info("登录用户ID【{}】", user.getUserId());
        sAlliance.setMemberId(user.getUserId());
        business.insertSAlliance(sAlliance);
        return ResponseHelper.success();
    }

    @ApiOperation("用户端-查询当前用户可提交次数")
    @GetMapping(value = "/submitNums")
    public Response<Integer> submitNums() {
        LoginInfo user = SystemContext.getUser();
        return ResponseHelper.success(10 - business.selectSubmitNums(user.getUserId()));
    }
}
